home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
taropyon
/
splib
/
splib.lzh
/
PRG
/
ZMODEM
/
RZ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-11
|
35KB
|
1,631 lines
#define __TOWNS__
#define VERSION "3.04 02-20-91"
#define PUBDIR "/usr/spool/uucppublic"
/*
* rz.c By Chuck Forsberg
*
* A program for Unix to receive files and commands from computers running
* Professional-YAM, PowerCom, YAM, IMP, or programs supporting XMODEM. rz
* uses Unix buffered input to reduce wasted CPU time.
*
*
* This version implements numerous enhancements including ZMODEM Run Length
* Encoding and variable length headers. These features were not funded by
* the original Telenet development contract.
*
* This software may be freely used for non commercial and educational (didactic
* only) purposes. This software may also be freely used to support file
* transfer operations to or from licensed Omen Technology products. Any
* programs which use part or all of this software must be provided in source
* form with this notice intact except by written permission from Omen
* Technology Incorporated.
*
* Use of this software for commercial or administrative purposes except when
* exclusively limited to interfacing Omen Technology products requires a per
* port license payment of $20.00 US per port (less in quantity). Use of
* this code by inclusion, decompilation, reverse engineering or any other
* means constitutes agreement to these conditions and acceptance of
* liability to license the materials and payment of reasonable legal costs
* necessary to enforce this license agreement.
*
*
* Omen Technology Inc FAX: 503-621-3745 Post Office Box 4681
* Portland OR 97208
*
* This code is made available in the hope it will be useful, BUT WITHOUT ANY
* WARRANTY OF ANY KIND OR LIABILITY FOR ANY DAMAGES OF ANY KIND.
*
*
*
* Iff the program is invoked by rzCOMMAND, output is piped to "COMMAND
* filename" (Unix only)
*
* Some systems (Venix, Coherent, Regulus) may not support tty raw mode read(2)
* the same way as Unix. ONEREAD must be defined to force one character reads
* for these systems. Added 7-01-84 CAF
*
* Alarm signal handling changed to work with 4.2 BSD 7-15-84 CAF
*
* NFGVMIN Updated 2-18-87 CAF for Xenix systems where c_cc[VMIN] doesn't work
* properly (even though it compiles without error!),
*
* SEGMENTS=n added 2-21-88 as a model for CP/M programs for CP/M-80 systems
* that cannot overlap modem and disk I/O.
*
* -DMD may be added to compiler command line to compile in Directory-creating
* routines from Public Domain TAR by John Gilmore
*
* HOWMANY may be tuned for best performance
*
* USG UNIX (3.0) ioctl conventions courtesy Jeff Martin */
#define LOGFILE "/tmp/rzlog"
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include <ctype.h>
#include <errno.h>
extern int errno;
#ifdef __TOWNS__
# include <string.h>
# include <stdarg.h>
# include <stdlib.h>
# include <direct.h>
# include <stat.h>
# include <sys/types.h>
# include <sys/utime.h>
# include <io.h>
# include <time.h>
# include <splib.h>
# include <fslib.h>
# include "usrlib.h"
# include "rsctrl.h"
# include "flib.h"
# include "msgdat.h"
# ifdef __HIGHC__
# pragma On(Align_labels);
# endif
extern int RsPort;
# define _FSTAT_IGN
# define MD
#endif
#include "prot.h"
#include "rz.h"
int Zmodem = 0; /* ZMODEM protocol requested */
int Nozmodem = 0; /* If invoked as "rb" */
unsigned Baudrate = 2400;
unsigned Effbaud = 2400;
#include "rbsb.c" /* most of the system dependent stuff here */
#include "crctab.c"
FILE *fout = NULL;
/*
* Routine to calculate the free bytes on the current file system ~0 means
* many free bytes (unknown)
*/
static long getfree(void)
{
#ifdef __TOWNS__
int drv;
int tf, wf;
if ( (drv = FS_getdrv()) >= 0 )
{
if ( FS_get_dskFree( drv, &tf, &wf) == NORMAL )
return (long)tf;
}
#endif
return (~0L); /* many free bytes ... */
}
int Lastrx;
long rxbytes;
int Crcflg;
int Firstsec;
int Eofseen; /* indicates cpm eof (^Z) has been received */
int errors;
int Restricted = 0; /* restricted; no /.. or ../ in filenames */
#ifdef ONEREAD
/* Sorry, Regulus and some others don't work right in raw mode! */
int Readnum = 1; /* Number of bytes to ask for in read() from
* modem */
#else
int Readnum = HOWMANY; /* Number of bytes to ask for in read() from
* modem */
#endif
#define DEFBYTL 2000000000L /* default rx file size */
long Bytesleft; /* number of bytes of incoming file left */
long Modtime; /* Unix style mod time for incoming file */
int Filemode; /* Unix style mode for incoming file */
long Totalleft;
long Filesleft;
char Pathname[PATHLEN];
char *Progname; /* the name by which we were called */
int Batch = 0;
int Topipe = 0;
int Verbose = 0;
int Thisbinary; /* current file is to be received in bin mode */
int Blklen; /* record length of received packets */
#ifdef SEGMENTS
int chinseg = 0; /* Number of characters received in this data seg */
char secbuf[1 + (SEGMENTS + 1) * 1024];
#else
char secbuf[1025];
#endif
char linbuf[HOWMANY];
int Lleft = 0; /* number of characters in linbuf */
time_t timep[2];
char zconv; /* ZMODEM file conversion request */
char zmanag; /* ZMODEM file management request */
char ztrans; /* ZMODEM file transport request */
int Zctlesc; /* Encode control characters */
int Zrwindow = 1400; /* RX window size (controls garbage count) */
jmp_buf tohere; /* For the interrupt on RX timeout */
#define xsendline(c) sendline(c)
#include "zm.c"
#include "zmr.c"
int tryzhdrtype = ZRINIT; /* Header type to send corresponding
* to Last rx close */
#ifdef __TOWNS__
void signal_func(int level)
{
}
/* called by signal interrupt or terminate to clean things up */
void bibi(int n)
{
if (Zmodem)
zmputs(Attn);
canit();
mode(0);
USR_fprintf(stderr, "rz: caught signal %d; exiting", n);
cucheck();
EXIT(128 + n);
}
#else
void alrm(int level)
{
longjmp(tohere, -1);
}
/* called by signal interrupt or terminate to clean things up */
bibi(int n)
{
if (Zmodem)
zmputs(Attn);
canit();
mode(0);
fprintf(stderr, "rz: caught signal %d; exiting", n);
cucheck();
exit(128 + n);
}
#endif
void zm_main(int argc, char *argv[])
{
register char *cp;
register npats;
char *virgin, **patts;
int exitcode = 0;
Rxtimeout = 100;
// setbuf(stderr, NULL);
#if 0
if ((cp = getenv("SHELL")) && (substr(cp, "rsh") || substr(cp, "rksh")))
Restricted = TRUE; /* ɺî└ */
#endif
from_cu();
chkinvok(virgin = argv[0]); /* if called as [-]rzCOMMAND set flag */
npats = 0;
while (--argc)
{
cp = *++argv;
if (*cp == '-')
{
while (*++cp)
{
switch (*cp)
{
case '\\':
cp[1] = toupper(cp[1]);
continue;
case 'c':
Crcflg = TRUE;
break;
case 'e':
Zctlesc = 1;
break;
case 't':
if (--argc < 1)
{
usage();
}
Rxtimeout = atoi(*++argv);
if (Rxtimeout < 10 || Rxtimeout > 1000)
usage();
break;
case 'w':
if (--argc < 1)
{
usage();
}
Zrwindow = atoi(*++argv);
break;
case 'v':
++Verbose;
break;
default:
usage();
}
}
} else if (!npats && argc > 0)
{
if (argv[0][0])
{
npats = argc;
patts = argv;
}
}
}
if (npats > 1)
usage();
if (Batch && npats)
usage();
#ifndef __TOWNS__
if (Verbose)
{
if ( freopen(LOGFILE, "a", stderr) == NULL )
{
printf("Can't open log file %s\n", LOGFILE);
exit(0200);
}
// setbuf(stderr, NULL);
USR_fprintf(stderr, "argv[0]=%s Progname=%s\n", virgin, Progname);
}
#endif
if (Fromcu)
{
if (Verbose == 0)
Verbose = 2;
}
#ifdef __TOWNS__
USR_fprintf(stderr,"\n");
USR_fprintf(stderr,"rz ver.%s for TownsOS", MAIN_VER );
USR_fprintf(stderr," orignal rz %s\n\n", VERSION);
#else
vfile("%s %s for %s\n", Progname, VERSION, OS);
#endif
mode(1); /* save old tty stat, set